package com.itfallrain.controller;

import com.itfallrain.common.UserAuth;
import com.itfallrain.entity.Car;
import com.itfallrain.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/che")
public class CarController {
    @Autowired
    private CarService carService;
    @UserAuth(6)
    @RequestMapping("/car")
    @ResponseBody
    public Object car(int page ,int limit){
        Map<String,Object> map=new HashMap();
        map.put("code",0);
//        msg新增，删除，修改状态返回
        map.put("msg","");
        map.put("count",carService.getCarCount());
        map.put("data",carService.getAll(page, limit));
        return map;
    }
//    新增客户信息
    @RequestMapping("/adds")
    @ResponseBody
    public Object add(Car car){
        Map<String,Object> map=new HashMap<String, Object>();
        if(carService.selectAlls(car)==1){
            map.put("code",1);
            map.put("msg","新增成功");
        }else {
            map.put("code",0);
            map.put("msg","新增失败");
        }
            return map;
    }
//    删除客户信息
    @RequestMapping("/del")
    @ResponseBody
    public Object del(int id){
        Map<String,Object> map=new HashMap<String, Object>();
        if(carService.delectAlls(id)==1){
            map.put("code",1);
            map.put("msg","删除成功");
        }else {
            map.put("code",0);
            map.put("msg","删除失败");
        }
        return map;
    }
//    修改客户信息
    @RequestMapping("/edit")
    @ResponseBody
    public Object edit(Car car){
        Map<String,Object> map=new HashMap<String, Object>();
        System.out.println(carService.updataAlls(car));
        if(carService.updataAlls(car)==1){
            map.put("code",1);
            map.put("msg","修改成功！！");
        }else {
            map.put("code",0);
            map.put("msg","修改失败");
        }
        return map;
    }

}
